package com.rongji.dfish.ui.form;

import java.util.List;



/**
 * Radio 为单选按钮标签
 * @author DFish Team
 * @version 1.1
 * @since XMLTMPL 1.0
 */
public final class Radiogroup extends AbstractBoxgroup<Radiogroup,Radio,String> {

	/**
	 * @param name
	 * @param label
	 * @param value
	 * @param options
	 */
	public Radiogroup(String name, String label, String value,
			List<?> options) {
		super(name, label, value, options);
	}
	@Override
	protected Radio buildOption(Option o) {
		//FIXME 确认 这样构建json会多一个"type":"radio",的流量
		return new Radio(null,null,o.getChecked(),o.getValue()==null?null:o.getValue().toString(),o.getText());
	}
	public String getType() {
		return "radiogroup";
	}

	@Override
	public Radiogroup setValue(Object value) {
		value=this.value=toString(value);
		for (Radio r : nodes) {
			boolean checked =value != null&&value.equals(r.getValue());
			r.setChecked(checked?checked:null);
		}
		return this;
	}
}
